package com.cloud.core.graphx

import org.apache.spark.graphx.GraphLoader
import org.apache.spark.{SparkConf, SparkContext}

object TriangleCounting_01 {

  def main(args: Array[String]): Unit = {

    val sparkConf = new SparkConf()
      .setMaster("local")
      .setAppName("TriangleCounting_01")

    val sparkContext = new SparkContext(sparkConf)

    val graph = GraphLoader.edgeListFile(sparkContext, "data/facebook_combined.txt")

    println("Number of vertices : " + graph.vertices.count())
    println("Number of edges : " + graph.edges.count())

    graph.vertices.foreach(v => println(v))

    val tc = graph.triangleCount()

    tc.vertices.collect

    println("tc: " + tc.vertices.take(5).mkString("\n"));

    // println("Triangle counts: " + graph.connectedComponents.triangleCount().vertices.collect().mkString("\n"));

    println("Triangle counts: " + graph.connectedComponents.triangleCount().vertices.top(5).mkString("\n"));

    val sum = tc.vertices.map(a => a._2).reduce((a, b) => a + b)
    println("sum:" + sum)
  }

}
